package edu.ustb.service;
import java.util.List;

import edu.ustb.Mapper.AdminMapper;
import edu.ustb.Mapper.FunsMapper;
import edu.ustb.domain.Admin;
import edu.ustb.domain.Funs;
import edu.ustb.utils.MD5Util;
import edu.ustb.utils.MybatisUtil;

public class AdminServiceImpl implements AdminService{

	@Override
	public Admin isLogin(String adminName, String adminPass) {
	     AdminMapper adminMapper = MybatisUtil.getMapper(AdminMapper.class);
	     Admin admin = adminMapper.findByAdminName(adminName);

	     String md5 = MD5Util.getMd5(adminPass);
	     if (admin.getAdminPass().equals(md5)) {
	    	 FunsMapper funsMapper = MybatisUtil.getMapper(FunsMapper.class);
	    	 List<Funs> firstFuns = funsMapper.findByRoleId(admin.getAdminRole());
	    	 admin.getRole().setFirstFunList(firstFuns);
	    	 for(Funs fun:firstFuns)
	    	 {
	    		 List<Funs> secondFuns = funsMapper.findByFunId(fun.getFunId());
	    		 fun.setSecondFunList(secondFuns);
	    	 }
	    	 return admin;
	     }
	     else return null;
	}
}
